# 列表
name=['wq','123','as']
print(name[2])

# index位置
print(name.index('as'))

# count
print(name.count('wq'))

# len()长度
print(len(name))

# in not in 判断
print('wq' in  name)
print('wqq' not in name)

# 增加
name.append('gg')
print(name)
name.extend([12,20])
print(name)
name.insert(1,'qaz')
print(name)

# 删除
# del
# del name
# print(name)

pp=name.pop(1)
print(pp)
name.remove('wq')
print(name)
# name.clear()
# print(name)

# 修改
name[0]='wq1'
print(name)

# 逆致
name=[1,2,5,4,6,7]
name.reverse()
print(name)

name.sort()
print(name)
re=sorted(name)
print(re)

# 赋值
name1=name.copy()
print(name1)

name=['wq','we','er']
i =0
while i <len(name):
    print(name[i])
    i+=1

for i in  name:
    print(i)

# 嵌套列表
name=[[1,2],[3,5]]
print(name[1])
print(name[1][1])

# 元组 # 查找
t2=(10,20,30)
print(t2[1])

print(t2.index(10))
print(t2.count(20))
print(len(t2))

# 修改
tu3=(10,[10,20])
tu3[1][0]='wer'
print(tu3)

# 字典
# 修改
dict1={'name':'wq','age':'18'}
dict1['name']='gyy'
print(dict1)
dict1['id']=1
print(dict1)

# 删除
# del dict1['name']
# print(dict1)

# 清空
# dict1.clear()
# print(dict1)

# 查
print(dict1['id'])

# get
print(dict1.get('name'))

# keys
print(dict1.keys())

# values
print(dict1.values())

# items
print(dict1.items())

# 遍历keys
for key in dict1.keys():
    print(key)

# 遍历values
for v in dict1.values():
    print(v)

# # 遍历元素
for t in  dict1.items():
    print(t)

# 遍历键值对
for k ,v in dict1.items():
    print(f'{k}={v}')

# 集合
# 增加
s1={10,20}
s1.add(30)
print(s1)
s1.add(10)
print(s1)

s1.update([40,50])
print(s1)

s1.remove(10)
print(s1)

s1.discard(20)
print(s1)

s11=s1.pop()
print(s11)

# in not in
print(20 in s1)
print(20 not in s1)

# enumerate
list1=[1,2,3,4]
for i in enumerate(list1):
    print(i)

# 列表推导式
list1=[ i for i in  range(10)]
print(list1)

list2=[i for i in range(10) if i % 2 ==0]
print(list2)

list1=[(i,j) for i in range(1,3) for j in range(3)]
print(list1)

# 字典推导式
dict1={i:i **2 for i in range(1,5)}
print(dict1)

list1=['name','wq']
list2=['age',18]
dict2={list1[i]:list2[i] for i in range(len(list1))}
print(dict2)



# 集合推导式
list1={1,2,3}
set1={i**2 for i in list1}
print(set1)